package moonstruckdrops.page;

import java.util.List;

import moonstruckdrops.dao.EntryDao;
import moonstruckdrops.dto.EntryDto;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

public class EntryListPage extends WebPage{
	
	public EntryListPage(){
		EntryDao dao = new EntryDao();
		List<EntryDto> entities = dao.getEntry();
		
		ListView<EntryDto> list=new ListView<EntryDto>("list",entities){
			private static final long serialVersionUID = 1L;
			protected void populateItem(ListItem<EntryDto> item){
				final EntryDto entity=item.getModelObject();
				Link<Void> link=new Link<Void>("link"){
					private static final long serialVersionUID = 1L;
					public void onClick(){
						ModifiedEntryPage ModifiedEntry = new ModifiedEntryPage(entity.getId(),entity.getTitle(),entity.getEntry().getValue());
						setResponsePage(ModifiedEntry);
					}
				};
				String EntryTitle=entity.getId()+":"+entity.getTitle();
				link.add(new Label("Entry",EntryTitle));
				item.add(link);
			}
		};
		add(list);
	}

}